package com.lovo.Util;

import java.util.Scanner;

public class User {
    private String name;
    private String psd;
    private String email;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPsd() {
        return psd;
    }

    public void setPassword(String psd) {
        this.psd = psd;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public void a() {
        Scanner scan = new Scanner(System.in);
        System.out.println("请注册");
        //用户名
        while (true) {
            System.out.println("请输入id：（6-20位字母、数字、下划线）：");
            String username = scan.next();
            if (username.matches("^([0-9A-Za-z]|_){6,20}$")) {
                this.name = username;
                break;
            }
            System.out.println("请重新输入");
        }
        //密码
        while (true) {
            System.out.println("请输入密码：（6位以上的大小写字母、数字的组合，不能使用特殊字符）：");
            String inputPsw = scan.next();
            if (inputPsw.matches("^(?=.*\\d)(?=.*[a-z])(?=.*[A-Z])[a-zA-Z0-9]{6,}$")) {
                System.out.println("请确认密码");
                String agin = scan.next();
                if (agin.equals(inputPsw)) {
                    this.psd = agin;
                    break;
                }
                System.out.println("请重新输入");
            }
            System.out.println("请重新输入密码");
        }
        //邮箱
        while (true) {
            System.out.println("请输入邮箱：");
            String mail = scan.next();
            if (mail.matches("^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$")) {
                this.email = mail;
                System.out.println("注册成功");
                break;
            }
            System.out.println("请重新输入邮箱");
        }
    }

}
